﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Models;
using BLL;

namespace PCCS.Management.AdminManage
{
    public partial class AdminDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["admin"] != null)
                {
                    int id = Convert.ToInt32(Request.QueryString["id"]);
                    Admin admin = AdminManager.GetAdminByAdminID(id);
                    lblAdminName.Text = admin.AdminName;
                    txtAdminDesc.Text = admin.AdminDesc;
                }
                else
                {
                    Response.Write("<script language='javascript'>parent.location.href='../login.aspx';</script>");
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["id"]);
            Admin admin = AdminManager.GetAdminByAdminID(id);
            if (txtPassword.Text.Trim() != "")
            {
                admin.PassWord = txtPassword.Text.Trim();
            }
            admin.AdminDesc = txtAdminDesc.Text.Trim();
            AdminManager.ModifyAdmin(admin);

            //日志
            Models.AdminLog log = new Models.AdminLog();
            int logId = Convert.ToInt32(Session["admin"].ToString());
            string logName = AdminManager.GetAdminByAdminID(logId).AdminName;
            log.AdminName = logName;
            log.LogTime = DateTime.Now;
            log.LogDesc = "修改管理员" + admin.AdminName + "信息。";
            AdminLogManager.AddAdminLog(log);

            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('成功修改管理员信息');", true);
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminList.aspx");
        }
    }
}
